
const app = getApp()

Page({
  data: {
    statusBarHeight:app.statusBarHeight, //获取状态栏高度
    rankingHeight:app.rankingHeight,//标题宽度

    ballAll:[//抽奖球
      {url:'../../assets/img/ball1.png',class:'ball_1',startClass:'weiyi_1',winning_name:'重庆融创渝乐小镇4项青年门票'},
      {url:'../../assets/img/ball2.png',class:'ball_2',startClass:'weiyi_2',winning_name:'重庆融创渝乐小镇4项亲子门票（一大一小）'},
      {url:'../../assets/img/ball3.png',class:'ball_3',startClass:'weiyi_3',winning_name:'重庆雪世界滑雪延时票'},
      {url:'../../assets/img/ball4.png',class:'ball_4',startClass:'weiyi_4',winning_name:'重庆融创水世界通票（抽奖）'},
      {url:'../../assets/img/ball5.png',class:'ball_5',startClass:'weiyi_5',winning_name:"重庆融创海世界通票（抽奖）"},
      {url:'../../assets/img/ball1.png',class:'ball_6',startClass:'weiyi_6',winning_name:'重庆融创渝乐小镇通票（抽奖）'},
      {url:'../../assets/img/ball2.png',class:'ball_7',startClass:'weiyi_7',winning_name:'重庆融创雪世界通票（抽奖）'},
      {url:'../../assets/img/ball3.png',class:'ball_8',startClass:'weiyi_8',winning_name:'旅行现金基金888（抽奖）'},
      {url:'../../assets/img/ball4.png',class:'ball_9',startClass:'weiyi_9',winning_name:'高德100元打车券'},
      {url:'../../assets/img/ball5.png',class:'ball_10',startClass:'weiyi_10',winning_name:'乡村基15元抵扣券'},
    ],
    is_animation:false,//是否动画
    remaining:3,//剩余数量
    winning_arr:[//奖池列表
      {name:"888元现金红包"},
      {name:"水陆雪海通票"},
      {name:"高德100元打车"},
      {name:"乡村基15元抵扣卷"},
    ],
    is_popup:false,
    is_winning:false,//是否刮奖
    winning_index:2,//中奖index

    is_goWining:false,//中奖动画
    start:false,//是否开始抽奖

    barrage_arr:[//弹幕列表
      {num:1.2,name:'重庆融创渝乐小镇4项青年门票'},
      {num:3.2,name:'重庆融创渝乐小镇4项亲子门票（一大一小）'},
      {num:0,name:'重庆雪世界滑雪延时票'},
      {num:2.9,name:'重庆融创水世界通票（抽奖）'},
      {num:2.3,name:'重庆融创海世界通票（抽奖）'},
    ],

  },

  onLoad() {
    
  },
  // 刮奖
  tombola(){
    this.setData({
      is_winning:true,
    })
  },
  // 领取
  receive(){
    wx.showToast({
      title: '领取成功',
    })
    this.escFun();
  },
  escFun(){
    this.setData({
      is_winning:false,
      is_popup:false,
    })
  },
  getRandomInt(min,max){
    let num = Math.floor(Math.random()*(max-min+1))+min;
    console.log(num)
    return num;
  },
  winningFun(){
    this.setData({
      is_winning:false,
      is_popup:true,
      winning_index:this.getRandomInt(0,9),
    })
  },
  // 充值
  topUp(){
    this.setData({
      remaining:3,
    })
    wx.showToast({
      title: '充值成功',
    })
  },
  animationFun(){
    if(this.data.remaining<=0){
      wx.showToast({
        title: '次数不足，请先充值',
        icon:'none'
      })
      return
    }
    if(this.data.is_animation){
      return false;
    }

    this.setData({
      remaining:this.data.remaining-1,
      is_animation:true,
      start :true,
    })
    setTimeout(()=>{
      this.setData({
        is_goWining:true,
      })
    },2000)
    setTimeout(()=>{
      this.setData({
        is_animation:false,
        start:false,
        is_goWining:false,
      })
      this.winningFun();
    },3000)
  },
})
